package wangwenjun.phase2.concurrencypattern.balking;

import util.ThreadUtil;

import java.io.IOException;

/**
 * @author ChangLiang
 * @date 2020/6/16
 */
public class AutoSaveThread extends Thread {

    private final Document document;

    public AutoSaveThread(Document document) {
        super("document-auto-save-thread");
        this.document = document;
    }

    @Override
    public void run() {
        while (true) {
            try {
                document.save();
                ThreadUtil.sleepForMilliSecondsWithThrowable(1_000);
            } catch (IOException | InterruptedException e) {
                break;
            }
        }
    }
}
